package com.pybox.api;

import com.pybox.aop.Mylog;
import com.pybox.dto.Result;
import com.pybox.dto.TCabinetsDto;
import com.pybox.dto.TUsersDto;
import com.pybox.entity.TVehicle;
import com.pybox.service.TVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LeiYang
 * @title: TVehicleApi
 * @projectName pybox
 * @description: 车型管理API接口
 * @date 2019/7/2214:30
 */
@RequestMapping("/Vehicle")
@Api(tags = "Vehicle管理接口")
@RestController
public class TVehicleApi {

    @Autowired
    private TVehicleService vehicleService;

    @ApiOperation(value = "分页查询Vehicle", notes = "分页查询Vehicle")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
            //@ApiImplicitParam(name = "Id", value = "Id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "model", value = "model", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "brand", value = "brand", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "branch", value = "branch", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TVehicle>> page(
            @RequestParam(required = false) String model,
            @RequestParam(required = false) String brand,
            @RequestParam(required = false) String branch,
          //  @RequestParam(required = false) String Id,
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize) {
        Map<String, String> params = new HashMap<>();

        params.put("model", model);
        params.put("brand", brand);
        params.put("branch", branch);
       // params.put("Id", Id);
        return Result.ok(vehicleService.page(pageNo, pageSize, params));
    }

    //根据Id查询车型
    @ApiOperation(value = "根据Id查询Vehicle", notes = "查询Vehicle")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "path")
    public Result<TVehicle> detail(@PathVariable("id") Integer id) {

        return Result.ok(vehicleService.detail(id));
    }

    //更新Vehicle
    @ApiOperation(value = "更新Vehicle", notes = "更新Vehicle")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)

    public Result<Boolean> update(@RequestBody TVehicle dto) {

        vehicleService.update(dto);

        return Result.ok(true);
    }

    //根据Id删除Vehicle
    @ApiOperation(value = "根据Id删除Vehicle", notes = "根据Id删除Vehicle")
    @Mylog(value = "删除了车型")
    @RequestMapping(value = "/remove/{id}", method = RequestMethod.DELETE)
    public Result<Boolean> update(@PathVariable("id") Integer id) {
        vehicleService.remove(id);
        return Result.ok(true);
    }
}
